home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
QRZ! Ham Radio 8
/
QRZ Ham Radio Callsign Database - Volume 8.iso
/
pc
/
files
/
t_unix
/
bs941029.tgz
/
bbsx-941029.tar
/
bbsx
/
life.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-10-29
|
3KB
|
142 lines
#define _HPUX_SOURCE
#define STD_LIFETIME 15
#include <stdio.h>
#include <fcntl.h>
#include <pwd.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/time.h>
#include <fnmatch.h>
#include "bbs.h"
#include "bbs.hd"
const struct cmdtable cmdtable[1];
/*---------------------------------------------------------------------------*/
int main(int argc, char **argv)
{
FILE * fp, *fp1;
static int fdindex;
char buf[1024];
char line[80];
char junk[1024];
int fd,param;
int i,ok;
struct index index;
long now,inptime;
struct tm utctime;
struct lifetime {
char area[80];
int lt;
struct lifetime *next;
};
struct lifetime *lifetime, *pt, *next;
int lifetm;
int other;
struct passwd *pw;
if (getuid()) {
pw = getpwnam(bbsadm);
if(getuid() != pw->pw_uid) {
perror("permission denied");
return 1;
}
}
if (chdir(WRKDIR)) {
mkdir(WRKDIR, 0755);
if(chdir(WRKDIR)) halt();
}
read_config();
if ((fdindex = open(INDEXFILE, O_RDWR, 0644)) < 0) return 1;
pt=malloc(sizeof(*pt));
next=lifetime=pt;
pt->next=(struct lifetime *) NULL;
if (fp = fopen(LIFEFILE, "r")) {
while(!feof(fp)) {
fgets(line,80,fp);
param=sscanf(line,"%s %d%s",pt->area,&(pt->lt), junk);
if (param > 1 && *(pt->area) != '#') {
strupc(pt->area);
if (next=malloc(sizeof(*pt))) {
pt->next=next;
pt=next;
pt->next=(struct lifetime *) NULL;
}
else {
printf("%s", "not enough memory\n");
return;
}
}
}
fclose(fp);
pt = lifetime;
while (pt->next != (struct lifetime *) NULL &&
strcmp(pt->area,"OTHER")) {
pt=pt->next;
}
if (!strcmp(pt->area,"OTHER"))
other=pt->lt;
else
other=STD_LIFETIME;
for (; ; ) {
if (read(fdindex, (char *) &index, sizeof(index)) != sizeof(index)) goto stop;
if (!(index.flags & DELETED)) {
lifetm= (index.lifetime_h << 8) + (index.lifetime_l);
time(&now);
inptime=(long) ((now-index.date)/86400L);
ok=1;strupc(index.to);
pt = lifetime;
while (pt->next != (struct lifetime *) NULL && ok) {
if (fnmatch(pt->area, index.to, FNM_CASEFOLD) == FNM_NOMATCH)
ok = 1;
else
ok = 0;
if (ok) pt=pt->next;
}
if (!ok) {
if (pt->lt)
if (lifetm > pt->lt || !lifetm)
lifetm=pt->lt;
}
if (ok)
if (lifetm > other || !lifetm)
lifetm=other;
if (lifetm <= inptime && lifetm) {
if (strcmp(pt->area,"B")) {
strcpy(index.to,"B");
strcpy(index.at,Myhostname);
index.date = time((long *) 0);
}
else {
unlink(getfilename(index.mesg));
index.flags = index.flags | DELETED;
}
if (lseek(fdindex, -sizeof(struct index), SEEK_CUR) < 0) return -1;
if (write(fdindex, &index, sizeof(struct index)) != sizeof(struct index))
return -1;
}
}
}
}
stop:
close(fdindex);
return 0;
}